export const useGeojson = (emberbox: any) => {
  let CN = "";
  let US = "";
  let Upway = "";
  let Indoor = "";
  // geojson显示单元
  const showChina = () => {
    if (emberbox.current === null) return;
    emberbox.current.geojsonManage
      .addJsonByUrl("/json/China.json")
      .then((id: string) => {
        CN = id;
        console.log("CN", CN);
      });
  };
  const removeChina = () => {
    if (emberbox.current === null) return;
    emberbox.current.geojsonManage.removeJson(CN);
  };
  const showAmerican = () => {
    if (emberbox.current === null) return;
    US = emberbox.current.geojsonManage
      .addJsonByUrl(
        "https://docs.mapbox.com/mapbox-gl-js/assets/us_states.geojson"
      )
      .then((id: string) => {
        US = id;
        console.log("US", US);
      });
  };

  const removeAmerican = () => {
    if (emberbox.current === null) return;
    emberbox.current.geojsonManage.removeJson(US);
  };

  const addUpway = () => {
    if (emberbox.current === null) return;
    emberbox.current.geojsonManage
      .addJsonByUrl("/json/upway.json")
      .then((id: string) => {
        Upway = id;
        console.log("CN", CN);
      });
  };
  const removeUpway = () => {
    if (emberbox.current === null) return;
    emberbox.current.geojsonManage.removeJson(Upway);
  };
  const addIndoor = () => {
    if (emberbox.current === null) return;
    emberbox.current.geojsonManage
      .addIndoorJsonByUrl("/json/indoorexp.geojson")
      .then((id: string) => {
        Indoor = id;
        console.log("Indoor", Indoor);
      });
  };
  const removeIndoor = () => {
    if (emberbox.current === null) return;
    emberbox.current.geojsonManage.removeJson(Indoor);
  };
  return {
    showChina,
    removeChina,
    showAmerican,
    removeAmerican,
    addUpway,
    removeUpway,
    addIndoor,
    removeIndoor,
  };
};
